﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMvcStoreApplication.Models;
using System.Data;

namespace MyMvcStoreApplication.Repositories
{
    public class AlbumRepository : IGenericRepository<Album>, IDisposable
    {
        private MusicStoreEntities db = new MusicStoreEntities();

        public List<Album> GetAll()
        {
            return db.Albumes.
                OrderByDescending(a => a.Likes).
                ThenBy(a => a.Nombre).
                ToList();
        }

        public List<Artista> ReadArtistas()
        {
            return db.Artistas.
                OrderBy(a => a.Nombre).
                ToList();
        }

        public List<Genero> ReadGeneros()
        {
            return db.Generos.
               OrderBy(a => a.Nombre).
               ToList();
        }

        public Album Get(int id)
        {
            return db.Albumes.Find(id);
        }

        public void SaveNew(Album album)
        {
            db.Albumes.Add(album);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            db.Albumes.Remove(this.Get(id));
            db.SaveChanges();
        }

        public void SaveModify(Album album)
        {
            db.Entry(album).State = EntityState.Modified;
            db.SaveChanges();
        }

        public void Dispose()
        {
            db.Dispose();
        }
    }
}